﻿using System;
using System.Collections.Generic;

namespace QDT.Core.Projects.LoanAlgorithm
{
    /// <summary>
    /// 还款方式信息类
    /// </summary>
    public class AlgorithmInfo : Entity, IAggregeRoot {

        /// <summary>
        /// 每月付息还本
        /// </summary>
        public static AlgorithmInfo InterestOfMonth = new AlgorithmInfo(1, "付息还本", typeof(MonthInterestAlgorithm));

        public static IList<AlgorithmInfo> GetAlgorithmInfos()
        {
            return new List<AlgorithmInfo> {
                                                 InterestOfMonth
                                             };
        }

        public AlgorithmInfo() {
            IsEffect = true;
        }

        public AlgorithmInfo(int id,string name,Type type) :this(){

            ID = id;

            Name = name;

            Type = type;
        }

        private Type _repaymentType;

        /// <summary>
        /// 还款方式的名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 是否有效
        /// </summary>
        public bool IsEffect { get; set; }

        /// <summary>
        /// 还款方式类型的完全限定名
        /// </summary>
        public string TypeName { get; private set; }

        /// <summary>
        /// 还款方式的类型
        /// </summary>
        public Type Type {

            get {
                return _repaymentType;
            }
            set { 
                _repaymentType = value;
                TypeName = value.FullName;
            }
        }


        /// <summary>
        /// 通过项目，获得项目的还款方式对象
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public ILoanAlgorithm Instance(Project project) {
            return Activator.CreateInstance(Type, project) as ILoanAlgorithm;
        }


    }
}
